/**
 * @param {number} n
 * @return {boolean}
 */
var isHappy = function (n) {
    let res = sum(n)
    let obj = {}
    while(res != 1){
        if(res in obj) return false;
        obj[res] = 1
        res = sum(res)
    }
    return true
}

function sum(n){
    n = n + '';
    let sum = 0;
    for(let i of n){
        sum += i * i
    }
    return sum
}

var a = isHappy(19)
console.log(a);

